//
//  TestPageContentVC.swift
//  CooperSwift_Example
//
//  Created by 计海峰 on 2021/6/10.
//  Copyright © 2021 CocoaPods. All rights reserved.
//

import UIKit

import RxSwift
import JXSegmentedView

class TestPageContentVC: UIViewController {

    
    var second: Int?
    
    let btn = UIButton.init().then {
        $0.setTitle("按钮", for: .normal)
    }
    
    let disposeBag = DisposeBag()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .random()
        navigationItem.title = "测试页"
//        edgesForExtendedLayout = []
//        self.navigationController?.navigationBar.isTranslucent = false
        view.addSubview(btn)
        btn.snp.makeConstraints {
            $0.left.top.equalToSuperview().offset(20)
            $0.right.equalToSuperview().offset(-20)
            $0.height.equalTo(44)
        }
        
        btn.rx.tap.subscribe(onNext: { [self] in
//            log.error("xxx")
//            navigationController?.pushViewController(TestPageContentVC(), animated: true)
            
//            guard let app = UIApplication.shared.delegate as? AppDelegate else {
//                return
//            }
//
//            app.navVC.pushViewController(TestPageContentVC(), animated: true)
  
            
            if (second == 1) {
                UIApplication.currentVC()?.navigationController?.pushViewController(TestPageContentVC(), animated: true)
                return
            }
             
            let vc = TestPageContentVC()
            vc.second = 1
            present(vc, animated: true)
            
            
//            EnterpriseProvider.rx.request(.showCity("340000")).mapString().subscribe { str in
//                log.info(str)
//                [ProvinceModel].deserialize(from: str)?.forEach({ p in
//                    print(p?.province)
//                })
//            } onFailure: { error in
//                log.error(error)
//            } onDisposed: {
//                print("onDisposed")
//            }.disposed(by: disposeBag)
            
            
            
            
        }).disposed(by: disposeBag)
        
        navigationItem.rightBarButtonItems = [UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(test))]
    
    }
    
    @objc func test() {
        navigationController?.pushViewController(TestPageContentVC(), animated: true)
    }
    
}

extension TestPageContentVC: JXSegmentedListContainerViewListDelegate {
    func listView() -> UIView {
        return view
    }
}
